package com.heima.wemedia.controller.v1;

import com.heima.common.dtos.ResponseResult;
import com.heima.model.media.dtos.WmNewsDownOrUpDto;
import com.heima.model.media.dtos.WmNewsDto;
import com.heima.model.media.dtos.WmNewsPageReqDto;
import com.heima.wemedia.service.WmNewsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/api/v1/news")
public class WmNewsController {

    @Autowired
    private WmNewsService wmNewsService;

    @PostMapping("/page")
    public ResponseResult page(@RequestBody WmNewsPageReqDto dto){
        return wmNewsService.listPage(dto);

    }

    /**
     * 自媒体用户登录后，新增、修改、发布自媒体文章
     * @return
     */
    @PostMapping("/submit")
    public ResponseResult<Void> submit(@RequestBody WmNewsDto dto){
        wmNewsService.submit(dto);
        return ResponseResult.ok();
    }

    @GetMapping("/one/{id}")
    public ResponseResult findOne(@PathVariable Integer id ){
        return wmNewsService.findOne(id);

    }

    @PutMapping("/down_or_up")
    public ResponseResult downOrUp(@RequestBody WmNewsDownOrUpDto dto){
        wmNewsService.downOrUp(dto);
        return ResponseResult.ok();
    }

}
